package cn.zjq02.zuoye.One.three;

import java.util.ArrayList;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Text implements Comparator<Student> {

    public static void main(String[] args) {
        Student st1 = new Student("张三", 20, 90.0F);
        Student st2 = new Student("李四", 22, 90.0F);
        Student st3 = new Student("王五", 20, 95.0F);
        Student st4 = new Student("赵六", 22, 100.0F);
        Student st5 = new Student("田七", 26, 87.0F);
        List<Student> list = new ArrayList<>();
        list.add(st1);
        list.add(st2);
        list.add(st3);
        list.add(st4);
        list.add(st5);

        Collections.sort(list, new Comparator<Student>() {
            public int compare(Student o1, Student o2) {
                int result = (int) (o2.getGrade() - o1.getGrade());
                if (result == 0) {
                    result = o2.getAge() - o1.getAge();
                }
                return result;
            }
        });
        Collections.sort(list, new Text());
        for (Student studnet : list) {
            System.out.println(studnet);
        }
    }


    public int compare(Student o1, Student o2) {
        int result = o1.getGrade().compareTo(o1.getGrade());
        if(result == 0){
            return o1.getGrade().compareTo(o2.getGrade());
        }
        return result;
    }
}
